package org.example.springblog.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.springblog.model.UserInfo;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/3
 * Time: 19:24
 */
@Mapper
public interface UserInfoMapper {

    //根据用户名,查询用户信息
    @Select("select * from user_info where user_name = #{userName} and delete_flag = 0")
    UserInfo selectByUserName(UserInfo userInfo);

    //根据用户ID, 查询用户信息
    @Select("select * from user_info where id = #{id} and delete_flag = 0")
    UserInfo selectById(UserInfo userInfo);

    //增加用户发表的博客数量
    @Update("update user_info set blog_count = #{blogCount} where id = #{id}")
    Integer addBlogCountByUserId(UserInfo userInfo);

    //减少用户发表的博客数量
    @Update("update user_info set blog_count = #{blogCount} where id = #{id}")
    Integer subBlogCountByUserId(UserInfo loginUserInfo);

    //注册
    Integer register(UserInfo userInfo);

    //修改
    Integer modify(UserInfo userInfo);

    @Select("select * from user_info where delete_flag = 0 order by power desc,id asc")
    List<UserInfo> getUserList();
}
